package main

import (
	"fmt"
	. "whoops/leetcode/a234_回文链表/answer"
)

// link:https://leetcode-cn.com/problems/palindrome-linked-list/
func main() {
	nums := []int{1, 2, 2, 1}
	head := ArrayToList(nums)
	PrintList(head)
	fmt.Println(JudgeByTwoPoint(head))
}

/**
 * @Description:请判断一个链表是否为回文链表。
 */
func isPalindrome(head *ListNode) bool {
	return JudgeByRecursion(head)
}

//################ common ############
func ArrayToList(nums []int) *ListNode {
	length := len(nums)
	if length == 0 {
		return nil
	}
	head := &ListNode{Val: nums[0]}
	curr := head
	for i := 1; i < length; i++ {
		curr.Next = &ListNode{Val: nums[i]}
		curr = curr.Next
	}
	return head
}

/**
 * @Description: 打印链表
 * @param head 头结点
 */
func PrintList(head *ListNode) {
	for head != nil {
		fmt.Printf("%d ", head.Val)
		head = head.Next
	}
	fmt.Println()
}
